/**
 * 传入一个对象和布尔值，return根据ASCII码升序或者降序的对象
 * isSort: true代表升序，false代表降序
 * */
const sortASCII = (obj, isSort = true) => {
    let arr = [];
    Object.keys(obj).forEach((item) => arr.push(item));
    let sortArr = isSort ? arr.sort() : arr.sort().reverse();
    let sortObj = {};
    for (let i in sortArr) {
        sortObj[sortArr[i]] = obj[sortArr[i]];
    }
    return sortObj;
};

/**
 * 传入对象返回url参数
 * @param {Object} data {a:1}
 * @returns {string}
 */
const getParam = (data) => {
    let url = "";
    for (var k in data) {
        let value = data[k] !== undefined ? data[k] : "";
        url += `&${k}=${value}`;
    }
    return url ? url.substring(1) : "";
};

//时间戳产生的函数, 当前时间以证书表达，精确到秒的字符串
const createTimeStamp = () => {
    return parseInt(new Date().getTime() / 1000) + "";
};

export default {
    sortASCII,
    getParam,
    createTimeStamp,
};
